<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="中文名称" prop="nameCn">
        <el-input
          v-model="queryParams.nameCn"
          placeholder="请输入中文名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="中文标签" prop="aliaCn">
        <el-input
          v-model="queryParams.aliaCn"
          placeholder="请输入中文标签"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="英文名称" prop="nameEn">
        <el-input
          v-model="queryParams.nameEn"
          placeholder="请输入英文名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="ifSelect">
        <el-input
          v-model="queryParams.ifSelect"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="英文标签" prop="aliaEn">
        <el-input
          v-model="queryParams.aliaEn"
          placeholder="请输入英文标签"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="经度" prop="longitude">
        <el-input
          v-model="queryParams.longitude"
          placeholder="请输入经度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="纬度" prop="latitude">
        <el-input
          v-model="queryParams.latitude"
          placeholder="请输入纬度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属洲" prop="continent">
        <el-input
          v-model="queryParams.continent"
          placeholder="请输入所属洲"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属洲英文" prop="continentEn">
        <el-input
          v-model="queryParams.continentEn"
          placeholder="请输入所属洲英文"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属洲二级中文名" prop="continentSub">
        <el-input
          v-model="queryParams.continentSub"
          placeholder="请输入所属洲二级中文名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属洲二级英文名称" prop="continentSubEn">
        <el-input
          v-model="queryParams.continentSubEn"
          placeholder="请输入所属洲二级英文名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="国家代码" prop="code">
        <el-input
          v-model="queryParams.code"
          placeholder="请输入国家代码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="货币" prop="currency">
        <el-input
          v-model="queryParams.currency"
          placeholder="请输入货币"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="官方语言" prop="lang">
        <el-input
          v-model="queryParams.lang"
          placeholder="请输入官方语言"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="时区" prop="timezone">
        <el-input
          v-model="queryParams.timezone"
          placeholder="请输入时区"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="国土面积" prop="area">
        <el-input
          v-model="queryParams.area"
          placeholder="请输入国土面积"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="人口数量" prop="population">
        <el-input
          v-model="queryParams.population"
          placeholder="请输入人口数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属部门" prop="sysOrgCode">
        <el-input
          v-model="queryParams.sysOrgCode"
          placeholder="请输入所属部门"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="父级节点" prop="pid">
        <el-input
          v-model="queryParams.pid"
          placeholder="请输入父级节点"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="最上级id" prop="topId">
        <el-input
          v-model="queryParams.topId"
          placeholder="请输入最上级id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否有子节点" prop="hasChild">
        <el-input
          v-model="queryParams.hasChild"
          placeholder="请输入是否有子节点"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="国旗地址" prop="nationalFlag">
        <el-input
          v-model="queryParams.nationalFlag"
          placeholder="请输入国旗地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="简称" prop="abbreviation">
        <el-input
          v-model="queryParams.abbreviation"
          placeholder="请输入简称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="汉语拼音" prop="pinyin">
        <el-input
          v-model="queryParams.pinyin"
          placeholder="请输入汉语拼音"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="级别id" prop="levelId">
        <el-input
          v-model="queryParams.levelId"
          placeholder="请输入级别id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="名称首字母" prop="initial">
        <el-input
          v-model="queryParams.initial"
          placeholder="请输入名称首字母"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:region:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:region:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:region:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:region:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="regionList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="${comment}" align="center" prop="id" />
      <el-table-column label="中文名称" align="center" prop="nameCn" />
      <el-table-column label="中文标签" align="center" prop="aliaCn" />
      <el-table-column label="英文名称" align="center" prop="nameEn" />
      <el-table-column label="${comment}" align="center" prop="ifSelect" />
      <el-table-column label="英文标签" align="center" prop="aliaEn" />
      <el-table-column label="经度" align="center" prop="longitude" />
      <el-table-column label="纬度" align="center" prop="latitude" />
      <el-table-column label="所属洲" align="center" prop="continent" />
      <el-table-column label="所属洲英文" align="center" prop="continentEn" />
      <el-table-column label="所属洲二级中文名" align="center" prop="continentSub" />
      <el-table-column label="所属洲二级英文名称" align="center" prop="continentSubEn" />
      <el-table-column label="国家代码" align="center" prop="code" />
      <el-table-column label="货币" align="center" prop="currency" />
      <el-table-column label="官方语言" align="center" prop="lang" />
      <el-table-column label="时区" align="center" prop="timezone" />
      <el-table-column label="国土面积" align="center" prop="area" />
      <el-table-column label="人口数量" align="center" prop="population" />
      <el-table-column label="描述" align="center" prop="regionDesc" />
      <el-table-column label="地区描述英文" align="center" prop="regionDescEn" />
      <el-table-column label="所属部门" align="center" prop="sysOrgCode" />
      <el-table-column label="父级节点" align="center" prop="pid" />
      <el-table-column label="层级路径id集合" align="center" prop="pathIds" />
      <el-table-column label="最上级id" align="center" prop="topId" />
      <el-table-column label="是否有子节点" align="center" prop="hasChild" />
      <el-table-column label="国旗地址" align="center" prop="nationalFlag" />
      <el-table-column label="简称" align="center" prop="abbreviation" />
      <el-table-column label="汉语拼音" align="center" prop="pinyin" />
      <el-table-column label="级别id" align="center" prop="levelId" />
      <el-table-column label="名称首字母" align="center" prop="initial" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:region:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:region:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改【请填写功能名称】对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="中文名称" prop="nameCn">
          <el-input v-model="form.nameCn" placeholder="请输入中文名称" />
        </el-form-item>
        <el-form-item label="中文标签" prop="aliaCn">
          <el-input v-model="form.aliaCn" placeholder="请输入中文标签" />
        </el-form-item>
        <el-form-item label="英文名称" prop="nameEn">
          <el-input v-model="form.nameEn" placeholder="请输入英文名称" />
        </el-form-item>
        <el-form-item label="${comment}" prop="ifSelect">
          <el-input v-model="form.ifSelect" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="英文标签" prop="aliaEn">
          <el-input v-model="form.aliaEn" placeholder="请输入英文标签" />
        </el-form-item>
        <el-form-item label="经度" prop="longitude">
          <el-input v-model="form.longitude" placeholder="请输入经度" />
        </el-form-item>
        <el-form-item label="纬度" prop="latitude">
          <el-input v-model="form.latitude" placeholder="请输入纬度" />
        </el-form-item>
        <el-form-item label="所属洲" prop="continent">
          <el-input v-model="form.continent" placeholder="请输入所属洲" />
        </el-form-item>
        <el-form-item label="所属洲英文" prop="continentEn">
          <el-input v-model="form.continentEn" placeholder="请输入所属洲英文" />
        </el-form-item>
        <el-form-item label="所属洲二级中文名" prop="continentSub">
          <el-input v-model="form.continentSub" placeholder="请输入所属洲二级中文名" />
        </el-form-item>
        <el-form-item label="所属洲二级英文名称" prop="continentSubEn">
          <el-input v-model="form.continentSubEn" placeholder="请输入所属洲二级英文名称" />
        </el-form-item>
        <el-form-item label="国家代码" prop="code">
          <el-input v-model="form.code" placeholder="请输入国家代码" />
        </el-form-item>
        <el-form-item label="货币" prop="currency">
          <el-input v-model="form.currency" placeholder="请输入货币" />
        </el-form-item>
        <el-form-item label="官方语言" prop="lang">
          <el-input v-model="form.lang" placeholder="请输入官方语言" />
        </el-form-item>
        <el-form-item label="时区" prop="timezone">
          <el-input v-model="form.timezone" placeholder="请输入时区" />
        </el-form-item>
        <el-form-item label="国土面积" prop="area">
          <el-input v-model="form.area" placeholder="请输入国土面积" />
        </el-form-item>
        <el-form-item label="人口数量" prop="population">
          <el-input v-model="form.population" placeholder="请输入人口数量" />
        </el-form-item>
        <el-form-item label="描述" prop="regionDesc">
          <el-input v-model="form.regionDesc" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="地区描述英文" prop="regionDescEn">
          <el-input v-model="form.regionDescEn" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="所属部门" prop="sysOrgCode">
          <el-input v-model="form.sysOrgCode" placeholder="请输入所属部门" />
        </el-form-item>
        <el-form-item label="父级节点" prop="pid">
          <el-input v-model="form.pid" placeholder="请输入父级节点" />
        </el-form-item>
        <el-form-item label="层级路径id集合" prop="pathIds">
          <el-input v-model="form.pathIds" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="最上级id" prop="topId">
          <el-input v-model="form.topId" placeholder="请输入最上级id" />
        </el-form-item>
        <el-form-item label="是否有子节点" prop="hasChild">
          <el-input v-model="form.hasChild" placeholder="请输入是否有子节点" />
        </el-form-item>
        <el-form-item label="国旗地址" prop="nationalFlag">
          <el-input v-model="form.nationalFlag" placeholder="请输入国旗地址" />
        </el-form-item>
        <el-form-item label="简称" prop="abbreviation">
          <el-input v-model="form.abbreviation" placeholder="请输入简称" />
        </el-form-item>
        <el-form-item label="汉语拼音" prop="pinyin">
          <el-input v-model="form.pinyin" placeholder="请输入汉语拼音" />
        </el-form-item>
        <el-form-item label="级别id" prop="levelId">
          <el-input v-model="form.levelId" placeholder="请输入级别id" />
        </el-form-item>
        <el-form-item label="名称首字母" prop="initial">
          <el-input v-model="form.initial" placeholder="请输入名称首字母" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listRegion, getRegion, delRegion, addRegion, updateRegion } from "@/api/system/region";

export default {
  name: "Region",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      regionList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        nameCn: null,
        aliaCn: null,
        nameEn: null,
        ifSelect: null,
        aliaEn: null,
        longitude: null,
        latitude: null,
        continent: null,
        continentEn: null,
        continentSub: null,
        continentSubEn: null,
        code: null,
        currency: null,
        lang: null,
        timezone: null,
        area: null,
        population: null,
        regionDesc: null,
        regionDescEn: null,
        sysOrgCode: null,
        pid: null,
        pathIds: null,
        topId: null,
        hasChild: null,
        nationalFlag: null,
        abbreviation: null,
        pinyin: null,
        levelId: null,
        initial: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      listRegion(this.queryParams).then(response => {
        this.regionList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        nameCn: null,
        aliaCn: null,
        nameEn: null,
        ifSelect: null,
        aliaEn: null,
        longitude: null,
        latitude: null,
        continent: null,
        continentEn: null,
        continentSub: null,
        continentSubEn: null,
        code: null,
        currency: null,
        lang: null,
        timezone: null,
        area: null,
        population: null,
        regionDesc: null,
        regionDescEn: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        sysOrgCode: null,
        pid: null,
        pathIds: null,
        topId: null,
        hasChild: null,
        nationalFlag: null,
        abbreviation: null,
        pinyin: null,
        levelId: null,
        initial: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加【请填写功能名称】";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getRegion(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改【请填写功能名称】";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateRegion(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRegion(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除【请填写功能名称】编号为"' + ids + '"的数据项？').then(function() {
        return delRegion(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/region/export', {
        ...this.queryParams
      }, `region_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
